package cn.hl.hm.controller;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.hl.hm.dao.TFeedbackEntityMapper;
import cn.hl.hm.entity.TFeedbackEntity;
import cn.hl.hm.service.TFeedbackReplyService;
import cn.hl.hm.service.TFeedbackService;
import cn.hl.hm.util.InfoCode;
import cn.hl.hm.util.Result;
import cn.hl.hm.util.Tools;


@Controller
@RequestMapping("/backstageTFeedbackreplyController")
public class BackstageTFeedbackreplyController {
	private static Logger logger = Logger.getLogger(BackstageTFeedbackreplyController.class);
	@Autowired
	private TFeedbackReplyService tFeedbackReplyService; 
	@Autowired
	private TFeedbackEntityMapper tFeedbackmapper; 
	@Autowired
	private TFeedbackService tFeedbackService; 
	//查询单条反馈信息
	@RequestMapping(value = "/backstageFeedbackReply", method = RequestMethod.POST)
	 public
	    @ResponseBody
	    String backstageFeedbackReply(
	    		@RequestParam(value = "id", required = true) Integer id,
	    		@RequestParam(value = "replyContent", required = true) String replyContent,
	    		@RequestParam(value = "hid", required = true) Integer hid,
				@RequestParam(value = "mailbox", required = false) String mailbox,
	    		HttpServletRequest request, HttpServletResponse response) {
		try{
			if(Tools.isInteger(id) || Tools.isBank(replyContent) || Tools.isInteger(hid)){
				 Result.ok(null, InfoCode.FAILURE, response); 
				 return null;
			}
			String i=tFeedbackReplyService.insertTFeedbackReply(id, replyContent, hid, mailbox);
			
			 TFeedbackEntity tfe=tFeedbackService.selectfeedbackOne(id);
			 tfe.setIsReply(1);
			int j= tFeedbackmapper.updateByPrimaryKeySelective(tfe);
			 Result.ok(j, InfoCode.SUCCESS, response); 
			 return null;
		}catch(Exception e){
			e.printStackTrace();
			logger.error(e);
			Result.ok(null, InfoCode.FAILURE, response); 
		}
		    		 
						return null;
	
		}
}
